package com.lc.projects.sample.plan;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class CreateTxt {
	public static void main(String[] args) {
		String parentPath = "E:\\OneDrive\\create\\考研核心";
		List<String> files = getFileNames(parentPath);

		String startDateStr = "2017-06-01";
		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sd2 = new SimpleDateFormat("MM-dd");

		StringBuffer sb = new StringBuffer();
		try {
			Date startDate = sd.parse(startDateStr);
			Calendar cal = Calendar.getInstance();
			cal.setTime(startDate);
			int i = 1;
			for (String str : files) {
				sb.append(sd2.format(cal.getTime()));
				sb.append("\r\n");
				sb.append("考研核心第" + i + "天  ");
				sb.append("file 考研核心\\");
				sb.append(str);
				sb.append("\r\n");
				i++;
				cal.add(Calendar.DAY_OF_YEAR, 3);
			}

		} catch (ParseException e) {
			e.printStackTrace();
		}
		FileOutputStream out = null;
		try {
			out = new FileOutputStream("E:\\OneDrive\\create\\plan.txt");
			out.write(sb.toString().getBytes());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		System.out.println("Done.");
	}

	public static List<String> getFileNames(String parentPath) {
		List<String> list = new ArrayList<>();
		File parent = new File(parentPath);
		File[] files = parent.listFiles();
		for (File file : files) {
			list.add(file.getName());
		}

		return list;
	}
}
